package com.example.aircraftticketingsystemserver.utils;



import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


//统一返回结果的类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    /**
     * 状态码
     */
    private Integer code=0;
    /**
     * 消息提示
     */
    private String message="ok";
    /**
     * 返回数据
     */
    private Object data;

    public Result(Object data) {
        this.data = data;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 成功不返回数据
     * @return
     */
    public static Result ok(){
        return new Result();
    }

    /**
     * 成功返回数据
     * @param data
     * @return
     */
    public static Result ok(Object data) {
        return new Result(data);
    }
        /**
         * 失败 返回系统异常
         */
    public static Result error(){
        return new Result(-1,"系统异常");
    }

    /**
     * 失败 返回自定义消息
     * @param msg
     * @return
     */
    public static Result error(String msg){
        return new Result(-1,msg);
    }

}
